import os
import sys

gae_home_path = None
gaevc_config = None

def read_config():
  global gaevc_config
  import yaml
  basedir = os.path.dirname(__file__)
  config_file = os.path.join(basedir, 'gaevc.yaml')
  try:
     gaevc_config = yaml.load(file(config_file, 'r'))
  except yaml.YAMLError, exc:
     print "Error in reading configuration file:", exc
  print gaevc_config['GAE_HOME']
  if ( not gaevc_config ['GAE_HOME'] ):
     print "No GAE_HOME defined in file: ", config_file 
     os.exit()
   
def set_python_path():
   gae_home_path = gaevc_config['GAE_HOME']
   EXTRA_PATHS = [
     gae_home_path,
     os.path.join(gae_home_path, 'lib', 'antlr3'),
     os.path.join(gae_home_path, 'lib', 'django'),
     os.path.join(gae_home_path, 'lib', 'ipaddr'),
     os.path.join(gae_home_path, 'lib', 'webob'),
     os.path.join(gae_home_path, 'lib', 'yaml', 'lib'),
   ]
   sys.path = EXTRA_PATHS + sys.path
   
read_config()   
set_python_path()
